<div class="filter">
    <div class="f1 item" style="width: 140px;">
        <input type="text" class="am-form-field" placeholder="代理账号" />
    </div>
    <div class="f5 item" style="width: 120px;">
        <select data-am-selected>
            <option value="1,2,3">全部状态</option>
            <option value="1">已累积</option>
            <option value="2">已结算</option>
            <option value="3">已清除</option>
        </select>
    </div>
    <div class="f6 item" style="width: 120px;">
        <select data-am-selected>
            <option value="-1">审核状态</option>
            <option value="1">待审核</option>
            <option value="2">已通过</option>
        </select>
    </div>
    <div class="f9 item" style="width: 120px;">
        <input type="text" class="am-form-field" placeholder="起始月份" id="start"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>
    <div class="f10 item" style="width: 120px;">
        <input type="text" class="am-form-field" placeholder="结束月份" id="end"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>

    <div class="button item">
        <button type="button" class="am-btn am-btn-primary">查看</button>
    </div>
    <div class="clear"></div>
</div>

<!-- 代理模式1 -->
<div style="line-height: 32px; margin-top: 10px; background-color: #65f2fc; color: #000; text-indent: 5px;">
    代理模式：赔率差
</div>
<table class="am-table am-table-bordered am-table-radius am-table-striped am-table-compact mode1" id="result-table" 
    style="min-width: 800px;">
    <thead>
    <tr>
        <th>月份</th>
        <th>代理账号</th>
        <th>姓名</th>
        <th>有效会员</th>
        <th>达标用户</th>
        <th>赔率差额</th>
        <th>返水差额</th>
        <th>行政费用</th>
        <th>风险费用</th>
        <th>本月佣金</th>
        <th>累积佣金</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>

<!-- 代理模式2 -->
<div style="line-height: 32px; margin-top: 10px; background-color: #65f2fc; color: #000; text-indent: 5px;">
    代理模式：盈利抽成
</div>
<table class="am-table am-table-bordered am-table-radius am-table-striped am-table-compact mode2" id="result-table" 
    style="min-width: 800px;">
    <thead>
    <tr>
        <th>月份</th>
        <th>代理账号</th>
        <th>姓名</th>
        <th>有效会员</th>
        <th>达标用户</th>
        <th>会员盈利总额</th>
        <th>抽成百分比</th>
        <th>行政费用</th>
        <th>风险费用</th>
        <th>本月佣金</th>
        <th>累积佣金</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<div class="zxf_pagediv"></div>

<script>
    $(".f9 input").datepicker({format: 'yyyy-mm'});
    $(".f10 input").datepicker({format: 'yyyy-mm'});
    Util.restorePageFilter();

    var _f = Util.queryTemplate($("#result-table tbody"), ".zxf_pagediv", $(".button button"), function(page, size, cb) {
        var uid = $(".f1 input").val().trim();
        var state = $(".f5 select").val();
        var start = $(".f9 input").val();
        var end = $(".f10 input").val();
        var check = $(".f6 select").val();
        var data = {
            pageSize: size,
            pageNum: page,
            state: state,
        };
        if (uid) data.uid = uid;
        if (start) data.start = start;
        if (end) data.end = end;
        if (check != -1) data.check = check;

        Util.savePageFilter([".f1 input", ".f5 select", ".f9 input", ".f10 input"]);
        startLoading();
        CMD.stat_referee_query(data, function(r) {
            stopLoading();
            cb(r);
        });
    }, function(table, list, sum) {
        var table1 = $(".mode1 tbody"), table2 = $(".mode2 tbody");
        if (Util.isEmpty(list)) {
            table.append("<tr><td colspan='13'>暂无数据</tr>");
            return;
        }

        for (var i in list) {
            var o = list[i];
            var tr = $("<tr></tr>");
            tr.append("<td>" + o.month + "</td>");
            tr.append("<td>" + o.user.mobile + "</td>");
            tr.append("<td>" + (o.user.name || '') + "</td>");
            tr.append("<td>" + o.valid + "</td>");
            tr.append("<td>" + o.standard + "</td>");
            var t = table1;
            if (o.type == 1) {
                // 模式1
                tr.append("<td>" + o.profit/100 + "</td>");
                tr.append("<td>" + o.back/100 + "</td>");
            }
            else {
                t = table2;
            }

            // 行政费用
            var s = (o.adminFee/100 + "×" + o.adminRate + "%=") + (o.adminFee * o.adminRate / 10000);
            tr.append("<td>" + s + "</td>");

            // 风险费用
            var s = (o.riskFee/100 + "×" + o.riskRate + "%=") + (o.riskFee * o.riskRate / 10000);
            tr.append("<td>" + s + "</td>");

            tr.append("<td>" + o.commission/100 + "</td>");
            tr.append("<td>" + o.accumulate/100 + "</td>");

            // 状态
            if (o.state == 1) {
                tr.append("<td>已累积</td>");
            }
            else if (o.state == 2) {
                tr.append("<td>已结算</td>");
            }
            else if (o.state == 3) {
                tr.append("<td>已清除</td>");
            }

            // 操作
            var oper = '';
            if (o.check == 1) 
                var oper = '<button value="__id__" class="pass">通过</button>\
                    <button value="__id__" class="reject">驳回</button>';
            else if (o.check == 2) {
                oper = '已通过';
            }
            oper = oper.replace(/__id__/g, o.id);
            tr.append("<td>" + oper + "</td>");
            t.append(tr);
        }

        $("button.pass").click(function(e) {
            var id = $(e.currentTarget).attr("value");
            if (!confirm("审核通过后，佣金将直接打到代理余额，本操作不可撤回，确认审核通过？")) return;
            startLoading();
            CMD.stat_referee_pass(id, function() {
                stopLoading();
                _f();
            });
        })
        $("button.reject").click(function(e) {
            var id = $(e.currentTarget).attr("value");
            if (!confirm("确定驳回吗？")) return;
            startLoading();
            CMD.stat_referee_reject(id, "", function() {
                stopLoading();
                _f();
            });
        })
    });
</script>